import db.MYSQLControl;
import driver.PhantomJsDriver;
import driver.chromedriver;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import parse.priceParse;
import parse.priceParse_1;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class price_old_pau {
    public static void main(String[] args) throws InterruptedException, IOException {

        WebDriver driver = null;
        /*try {
            driver = chromedriver.getChromeDriver();
        } catch (IOException e) {
            e.printStackTrace();
        }*/
        driver = PhantomJsDriver.getPhantomJSDriver();


        List<String> result = readFileByLines("D:\\price.txt");
        for(String i :result){
            driver.get(i);
            Thread.sleep(4000);
            (new WebDriverWait( driver, 10)) .until(
                    ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id=\"car_tag\"]/nav/div/div/ul/li[2]/a"))
            ).click();
            Thread.sleep(2000);
            //System.out.println(driver.getCurrentUrl());
            List<model.model> data = priceParse_1.getData(null,null,null,driver.getPageSource());
            MYSQLControl.inserCarRecall(data);
        }
        driver.quit();


    }
    private static List<String> readFileByLines(String fileName) throws IOException {
        File file = new File(fileName);
        List<String> result = new ArrayList<String>();

        BufferedReader reader = null;

        try {



            reader = new BufferedReader(new FileReader(file));

            String tempString = null;

            int line = 1;

            // 一次读入一行，直到读入null为文件结束

            while ((tempString = reader.readLine()) != null) {

                // 显示行号
                result.add(tempString);




                line++;

            }

            reader.close();

        } catch (IOException e) {

            e.printStackTrace();

        } finally {

            if (reader != null) {

                try {

                    reader.close();

                } catch (IOException e1) {

                }

            }

        }
        return result;

    }
}
